﻿using System;
using System.Collections.Generic;

namespace DemoRealtimeData.Service
{
    public static class Common
    {
        public static readonly IDictionary<DataType, string> DataType2Description;

        static Common()
        {
            DataType2Description = new Dictionary<DataType, string>
            {
                {DataType.VM, "Voltage Magnitude"},
                {DataType.VA, "Voltage Angle"},
                {DataType.IM, "Current Magnitude"},
                {DataType.IA,"Current Angle"}
            };
        }

        public static Tuple<string, DataType> Parse(this string key)
        {
            string[] segments = key.Split('.');
            DataType dttype = (DataType)Enum.Parse(typeof(DataType), segments[1], true);
            return Tuple.Create(segments[0], dttype);
        }

        public static Database GetDatabase()
        {
            return new Database(Config.Default.Devices,
                new DataType[]
                    {
                        DataType.VM, 
                        DataType.VA, 
                        DataType.IM, 
                        DataType.IA
                    });
        }

        public static string MakeKey(string device, DataType dttype)
        {
            return string.Format("{0}.{1}", device, dttype);
        }
    }
}
